package com.vert.controller;

import com.alibaba.fastjson.JSONObject;
import com.vert.annotations.*;
import com.vert.db.DBSql;
import com.vert.service.CommonService;
import com.vert.utils.Results;

import java.util.List;
import java.util.Map;

/**
 * @Classname DemoController
 * @Description TODO
 * @Date 2022/5/25 0:11
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RouteMapping("/demo")
public class DemoController {

  @Autowired
  private CommonService commonService;

  @Autowired
  private DBSql dbSql;

  @GetMapping("/test1")
  public String test1(){
    String body=commonService.getBody();
    System.out.println(body);
    return body;
  }

  @GetMapping("/json")
  public JSONObject retuntJSON(){
    JSONObject obj = new JSONObject();
    obj.put("key","haha");
    obj.put("key1","haha,word");
    return obj;
  }

  @PostMapping("/json")
  public JSONObject testJSONObject(@RequestBody Map<String,Object> map){
      List<Map<String,Object>> mapList=dbSql.selectList("select * from m_note order by createtime desc limit 10");
      return Results.success(mapList);
  }

  @PostMapping("/json2")
  public JSONObject jsonController2(){
    List<Map<String,Object>> mapList=dbSql.selectList("select * from m_note order by createtime desc limit 1");
    return Results.success(mapList);
  }

}
